#coding: utf-8

import cv2
import time
from PIL import Image
from oled import OLed
from img2bin import img2bindata


def showVideo(
    video_fpath:str,
    threshold:int=200,
    oled_addr:str=0x3c,
    oled_width:int=128,
    oled_height:int=64
    ):
    oled = OLed(0x3C)
    oled.clear()
    time.sleep(1)

    cap = cv2.VideoCapture(video_fpath)
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        # print(frame)
        img = Image.fromarray(frame)
        # print(img)
        data = img2bindata(img, threshold=threshold, resize=(128, 64))
        # print(data)
        oled.showImageData(data)


if __name__ == '__main__':
    import fire

    fire.Fire(showVideo)
